package cn.edu.lingnan.controller;


import cn.edu.lingnan.entity.pojo.Point;
import cn.edu.lingnan.entity.pojo.Result;
import cn.edu.lingnan.service.PointService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/point")
public class PointController {

    @Autowired
    private PointService pointService;

    // 插入积分
    @PostMapping("/add")
    public Result add(@RequestParam("productId") Integer productId, @RequestParam("point") Integer point) {
        Point pointEntity = new Point();
        pointEntity.setProductId(productId);
        pointEntity.setPoint(point);

        // 使用 MyBatis-Plus 的 save 方法插入数据
        boolean isSaved = pointService.save(pointEntity);
  if (isSaved) {
      return Result.success();
  }
   return Result.error("积分添加失败");
    }



}
